package cmcc.dbi.service.impl;

import cmcc.dbi.dto.DbQueryDTO;
import cmcc.dbi.dto.ShellQueryDTO;
import cmcc.dbi.entity.InspectionItemRecord;
import cmcc.dbi.execJdbcUtil.*;
import cmcc.dbi.execUtil.ExeShellUtil;
import cmcc.dbi.service.InspectionRemoteConnService;
import com.alibaba.fastjson.JSONArray;
import com.jcraft.jsch.JSchException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
@Slf4j
public class InspectionRemoteConnServiceImpl implements InspectionRemoteConnService {

    private String dbType;
    private String dbIp;
    private String dbPort;
    private String dbUser;
    private String dbPass;


    @Override
    public JSONArray getRemoteSqlResult(List<InspectionItemRecord> scriptsLists, DbQueryDTO dbQueryDTO) throws SQLException {

        String dbType = dbQueryDTO.getDbType();

        JdbcFactory jdbcFactory = new JdbcFactory();
        JdbcUtil jdbcUtil = jdbcFactory.getJdbcUtil(dbType);

        JSONArray queryAllResult = jdbcUtil.getTargetResult(scriptsLists, dbQueryDTO);

        return queryAllResult;

    }


    @Override
    public JSONArray getRemoteShellResult(List<InspectionItemRecord> scriptLists, ShellQueryDTO shellQueryDTO) throws JSchException {
        ExeShellUtil exeShellUtil = new ExeShellUtil();
        JSONArray queryAllResult = exeShellUtil.getTargetResult(scriptLists, shellQueryDTO);

        return queryAllResult;

    }
}
